home *** CD-ROM | disk | FTP | other *** search
- package com.extensibility.esc;
-
- import com.extensibility.app.ApplicationPreferences;
- import com.extensibility.app.BaseApplication;
- import com.extensibility.app.BaseDocument;
- import com.extensibility.app.BasicURIResolver;
- import com.extensibility.app.Desktop;
- import com.extensibility.app.DialogFactory;
- import com.extensibility.app.UI;
- import com.extensibility.dom.AttrOwnerCache;
- import com.extensibility.dom.DOMUtilities;
- import com.extensibility.exv.ExtSchemaValidator;
- import com.extensibility.validation.Validator;
- import com.extensibility.validation.ValidatorError;
- import com.extensibility.validation.ValidatorErrorList;
- import com.extensibility.xml.ParserException;
- import com.extensibility.xml.SXE;
- import com.extensibility.xml.SchemaIntf;
- import com.extensibility.xml.URI;
- import com.ibm.xml.parsers.NonValidatingDOMParser;
- import java.awt.Cursor;
- import java.awt.event.ActionEvent;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.Reader;
- import java.io.Writer;
- import java.net.MalformedURLException;
- import java.util.Date;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.Vector;
- import javax.xml.parsers.DocumentBuilder;
- import javax.xml.parsers.DocumentBuilderFactory;
- import org.w3c.dom.Document;
- import org.xml.sax.EntityResolver;
- import org.xml.sax.InputSource;
- import org.xml.sax.SAXException;
- import org.xml.sax.SAXParseException;
-
- public class ESCDocument extends BaseDocument implements EntityResolver {
- public static final String ERROR = "error";
- public static final String NAME = "name";
- public static final String LOCATION = "location";
- public static final String NODE = "node";
- public static final String MESSAGE = "message";
- public static final String FILE = "file";
- public static final String ESC = "esc";
- public static final String DATE = "date";
- public static final String VALID = "valid";
- public static final String VIRGIN = "virgin";
- public static final String RECURSE = "recurse";
- public static final String EXPANDED = "expanded";
- public static final String USERSELECTED = "userSelected";
- protected Hashtable files = new Hashtable();
- protected ESCFileRepository repository = null;
- private String supportedFlavors;
- Hashtable resolvedEntities = new Hashtable();
- BasicURIResolver bur = new BasicURIResolver();
- protected NonValidatingDOMParser parser = new NonValidatingDOMParser();
-
- public ESCFile factoryESCFile(File var1, boolean var2) {
- if (this.repository == null) {
- this.repository = new ESCFileRepository();
- }
-
- ESCFile var3 = this.repository.factoryESCFile(var1, var2);
- if (!var3.isVirgin()) {
- this.addFile(var3);
- }
-
- return var3;
- }
-
- public synchronized boolean checkValidatePerformed() {
- Enumeration var1 = this.files.elements();
-
- while(var1.hasMoreElements()) {
- if (!((ESCFile)var1.nextElement()).isVirgin()) {
- return true;
- }
- }
-
- return false;
- }
-
- public void addFile(ESCFile var1) {
- String var2 = ((File)var1).getAbsolutePath();
- if (!this.files.containsKey(var2)) {
- this.files.put(var2, var1);
- }
-
- }
-
- public void deleteFiles(String[] var1) {
- for(int var2 = 0; var2 < var1.length; ++var2) {
- ESCFile var3 = this.factoryESCFile(new File(var1[var2]), true);
- if (var3.isUserSelected()) {
- if (((File)var3).isDirectory()) {
- Enumeration var4 = this.getFiles().elements();
-
- while(var4 != null && var4.hasMoreElements()) {
- ESCFile var5 = (ESCFile)var4.nextElement();
- String var6 = ((File)var5).getAbsolutePath();
- String var7 = var6.substring(0, var6.lastIndexOf(File.separator));
- if (!var5.isUserSelected() && var7.equals(var1[var2]) && ((File)var5).isFile() || var6.equals(var1[var2]) && ((File)var5).isDirectory()) {
- this.deleteFile(var6);
- }
- }
- }
-
- this.deleteFile(var1[var2]);
- }
- }
-
- }
-
- public void deleteFile(String var1) {
- if (this.files.containsKey(var1)) {
- this.files.remove(var1);
- ((BaseDocument)this).touch();
- }
-
- }
-
- public void removeFile(String var1) {
- this.deleteFile(var1);
- this.repository.removeESCFile(new File(var1));
- }
-
- public void deleteAll() {
- this.files.clear();
- ((BaseDocument)this).touch();
- }
-
- public ESCFile getFile(String var1) {
- return (ESCFile)this.files.get(var1);
- }
-
- public Hashtable getFiles() {
- return this.files;
- }
-
- public String getText() {
- Enumeration var1 = this.files.elements();
-
- String var2;
- ESCFile var3;
- for(var2 = ""; var1.hasMoreElements(); var2 = String.valueOf(var2).concat(String.valueOf(String.valueOf(var3.toString()).concat(String.valueOf("\n"))))) {
- var3 = (ESCFile)var1.nextElement();
- }
-
- return var2;
- }
-
- public ESCDocument(URI var1) {
- super(var1);
- }
-
- public ESCDocument() {
- this.repository = new ESCFileRepository();
- }
-
- public void write(Writer var1) throws IOException {
- SXE var2 = new SXE(var1);
- var2.writeHeader("1.0");
- var2.writeElem("esc", 0);
- Enumeration var3 = this.files.elements();
-
- while(var3.hasMoreElements()) {
- ESCFile var4 = (ESCFile)var3.nextElement();
- this.writeFile(var2, var4, 0);
- }
-
- var2.flush();
- }
-
- public void write(Writer var1, boolean var2) throws IOException {
- SXE var3 = new SXE(var1);
- var3.writeHeader("1.0");
- var3.writeElem("esc", 0);
- Enumeration var4 = this.files.elements();
-
- while(var4.hasMoreElements()) {
- ESCFile var5 = (ESCFile)var4.nextElement();
- if (var2 == var5.isValid()) {
- this.writeFile(var3, var5, 0);
- }
- }
-
- var3.flush();
- }
-
- private void writeFile(SXE var1, ESCFile var2, int var3) {
- var1.writeElem("file", var3 + 1);
- var1.writeAttr("name", ((File)var2).getAbsolutePath());
- var1.writeAttr("valid", String.valueOf(var2.isValid()));
- var1.writeAttr("virgin", String.valueOf(var2.isVirgin()));
- var1.writeAttr("userSelected", String.valueOf(var2.isUserSelected()));
- var1.writeAttr("date", var2.getValidationDate().toString());
- if (((File)var2).exists() && ((File)var2).isFile()) {
- Enumeration var4 = var2.getErrors().elements();
-
- while(var4.hasMoreElements()) {
- ParserException var5 = (ParserException)var4.nextElement();
- var1.writeElem("error", var3 + 2);
- var1.writeElem("location", var3 + 3);
- if (var5.getOffender() != null && var5.getOffender().length() > 0) {
- var1.writeRawText(var5.getSourceLinePos() > 0 ? String.valueOf(var5.getSourceLinePos()).concat(String.valueOf(" ")) : var5.getOffender());
- } else {
- var1.writeText(Integer.toString(var5.getSourceLinePos()));
- }
-
- var1.writeElem("message", var3 + 3);
- var1.writeRawText(String.valueOf(String.valueOf("<![CDATA[ ").concat(String.valueOf(var5.getMessage()))).concat(String.valueOf("]]>")));
- }
- } else if (((File)var2).exists()) {
- var1.writeElem("recurse", var3 + 2);
- var1.writeText(String.valueOf(var2.isRecursive()));
- var1.writeElem("expanded", var3 + 2);
- var1.writeText(String.valueOf(var2.isExpanded()));
- }
-
- }
-
- public void read(URI var1) {
- try {
- Reader var2 = var1.createReader();
- ESCDocHandler var3 = new ESCDocHandler(this);
- var3.parse(var2);
- } catch (Exception var4) {
- System.out.println("exception creating read in ESCDocument ");
- ((Throwable)var4).printStackTrace();
- }
-
- }
-
- public int getSize() {
- return this.files != null ? this.files.size() : 0;
- }
-
- public boolean save(ActionEvent var1) {
- boolean var2 = super.save(var1);
- if (var2) {
- this.updateTheRootName();
- }
-
- return var2;
- }
-
- public boolean saveAs(ActionEvent var1) {
- boolean var2 = super.saveAs(var1);
- if (var2) {
- this.updateTheRootName();
- }
-
- return var2;
- }
-
- protected File getSaveAsFile(ActionEvent var1) {
- String[] var2 = new String[]{"esc"};
- String var3 = "";
- BaseApplication.getApplication();
- ApplicationPreferences var4 = BaseApplication.getPreferences();
- String var5 = (String)((Hashtable)var4).get("last_esc_dir");
- if (var5 == null) {
- var5 = File.separator;
- }
-
- File var6 = DialogFactory.askNewFile(Desktop.getDialogParent(var1), var2, var3, var5);
- if (var6 != null) {
- ((Hashtable)var4).put("last_esc_dir", var6.getPath().toString());
- }
-
- return var6;
- }
-
- public void validateFiles(AWProgressBar var1, String[] var2) {
- for(int var3 = 0; var3 < var2.length; ++var3) {
- ESCFile var4 = this.factoryESCFile(new File(var2[var3]), false);
- if (((File)var4).isDirectory()) {
- Enumeration var5 = this.getSubfiles(var4, var4.isRecursive()).elements();
-
- while(var5 != null && var5.hasMoreElements()) {
- this.validateFile(var1, (ESCFile)var5.nextElement());
- }
- } else if (((File)var4).exists()) {
- this.validateFile(var1, var4);
- }
- }
-
- }
-
- public int getFileCount(boolean var1, String[] var2) {
- int var3 = 0;
-
- for(int var4 = 0; var4 < var2.length; ++var4) {
- ESCFile var5 = this.factoryESCFile(new File(var2[var4]), true);
- if (var5 != null && ((File)var5).exists() && (!var1 || !var5.isXMLFile())) {
- if (((File)var5).isDirectory()) {
- Hashtable var6 = this.getSubfiles(var5, var5.isRecursive());
- if (var1) {
- Enumeration var7 = var6.elements();
-
- while(var7.hasMoreElements()) {
- ESCFile var8 = (ESCFile)var7.nextElement();
- if (!var8.isXMLFile()) {
- ++var3;
- }
- }
- } else {
- var3 += var6.size();
- }
- } else {
- ++var3;
- }
- }
- }
-
- return var3;
- }
-
- public String[] getModifiedFiles(String[] var1) {
- Vector var2 = new Vector(15);
-
- for(int var3 = 0; var3 < var1.length; ++var3) {
- ESCFile var4 = this.factoryESCFile(new File(var1[var3]), true);
- if (var4 != null && ((File)var4).exists()) {
- if (((File)var4).isDirectory()) {
- Hashtable var5 = this.getModifiedFilesForDir(var4, var4.isRecursive());
- Enumeration var6 = var5.elements();
-
- while(var6.hasMoreElements()) {
- var2.addElement(var6.nextElement());
- }
- } else if (this.isModified(var4)) {
- var2.addElement(var4);
- }
- }
- }
-
- String[] var7 = new String[var2.size()];
- Enumeration var8 = var2.elements();
-
- for(int var9 = 0; var8.hasMoreElements(); var7[var9++] = ((ESCFile)var8.nextElement()).getAbsolutePath()) {
- }
-
- return var7;
- }
-
- private synchronized ESCFile validateFile(AWProgressBar var1, ESCFile var2) {
- if (var1 != null && var1.isAllowed()) {
- var1.next(((File)var2).getAbsolutePath());
- }
-
- if (var1 != null && var1.isAllowed() && var2.getExtension().equalsIgnoreCase("xml")) {
- ValidatorErrorList var33 = new ValidatorErrorList();
- boolean var34 = false;
-
- try {
- URI var5 = new URI(var2);
- this.bur.setBaseURI(var5);
- this.bur.autoCheckUnresolved(3000);
- this.bur.setSilent(true);
- DocumentBuilderFactory var39 = DocumentBuilderFactory.newInstance();
- var39.setValidating(false);
- DocumentBuilder var7 = var39.newDocumentBuilder();
- var7.setEntityResolver(this);
- InputSource var8 = createInputSource(var5);
- Document var9 = var7.parse(var8);
- SchemaIntf var10 = DOMUtilities.getSchema(var9, var5);
- Object[] var11 = DOMUtilities.getSchemaInfo(var9, var5);
- URI var12 = (URI)var11[0];
- if (var10 != null && var12 != null && var12.exists()) {
- Validator var40 = new Validator(var10);
- var33 = var40.validateDocument(var9, (AttrOwnerCache)null, this.bur);
- } else {
- ValidatorError var13 = new ValidatorError(1, 1, UI.getString("xml.validation.schema.not.found"));
- var33.add(var13);
- }
- } catch (SAXParseException var26) {
- ValidatorError var38 = new ValidatorError(var26.getLineNumber(), var26.getColumnNumber(), String.valueOf(UI.getString("xml.validation.sax.parse.exception")).concat(String.valueOf(((SAXException)var26).getMessage())));
- var33.add(var38);
- } catch (SAXException var27) {
- ValidatorError var37 = new ValidatorError(1, 1, UI.getString("xml.validation.schema.not.found"));
- var33.add(var37);
- } catch (MalformedURLException var28) {
- ValidatorError var36 = new ValidatorError(1, 1, UI.getString("xml.validation.schema.not.found"));
- var33.add(var36);
- } catch (FileNotFoundException var29) {
- ValidatorError var6 = new ValidatorError(1, 1, UI.getString("xml.validation.schema.not.found"));
- var33.add(var6);
- } catch (Throwable var30) {
- System.out.println(var30);
- var30.printStackTrace();
- } finally {
- var34 = var33.size() <= 0;
- var2.setValidationDate(new Date());
- var2.setValid(var34);
- var2.setVirgin(false);
- if (!var34) {
- if (var33 == null) {
- var2.setErrors((new Vector()).elements());
- } else {
- Enumeration var16 = var33.errors();
-
- Vector var17;
- ParserException var19;
- for(var17 = new Vector(); var16.hasMoreElements(); var17.addElement(var19)) {
- ValidatorError var18 = (ValidatorError)var16.nextElement();
- var19 = new ParserException(var18.getMessage(), "", var18.getErrorLine(), 0);
- if (var18.getErrorNode() != null) {
- if (var18.getErrorNode().getNodeType() == 3) {
- var19.setOffender(String.valueOf(String.valueOf(String.valueOf(String.valueOf(var18.getErrorNode().getParentNode().getNodeType()).concat(String.valueOf(":"))).concat(String.valueOf(var18.getErrorNode().getParentNode().getNodeName()))).concat(String.valueOf(": "))).concat(String.valueOf(var18.getErrorNode().getNodeValue())));
- } else {
- var19.setOffender(String.valueOf(String.valueOf(var18.getErrorNode().getNodeName()).concat(String.valueOf(": "))).concat(String.valueOf(var18.getErrorNode().getNodeValue())));
- }
- }
- }
-
- var2.setErrors(var17);
- }
- } else {
- var2.setErrors(new Vector());
- }
-
- this.addFile(var2);
- this.updateFile(var2);
- }
- } else if (var1 != null && var1.isAllowed()) {
- ExtSchemaValidator var3 = new ExtSchemaValidator();
- BaseApplication.getApplication();
- var3.setSchemaPath(String.valueOf(String.valueOf(BaseApplication.getHomePath()).concat(String.valueOf(File.separator))).concat(String.valueOf("sox")));
- URI var4 = new URI(var2);
- var3.validate(var4, var4, (String)null);
- var2.setValidationDate(new Date());
- var2.setValid(var3.isValid());
- var2.setVirgin(false);
- if (!var3.isValid()) {
- var2.setErrors(var3.getAllErrors());
- } else {
- var2.setErrors(new Vector());
- }
-
- Object var32 = null;
- this.addFile(var2);
- this.updateFile(var2);
- }
-
- return var2;
- }
-
- private void updateFile(ESCFile var1) {
- ESCFile var2 = (ESCFile)this.files.get(((File)var1).getAbsolutePath());
- if (var2 == null) {
- this.files.put(((File)var1).getAbsolutePath(), var1);
- } else {
- var1.setUserSelected(var2.isUserSelected());
- this.files.put(((File)var1).getAbsolutePath(), var1);
- }
-
- ((BaseDocument)this).touch();
- }
-
- public Hashtable getSubfiles(ESCFile var1, boolean var2) {
- ESCWindow var3 = (ESCWindow)Desktop.getFrontDocWindow();
- var3.setCursor(Cursor.getPredefinedCursor(3));
- var3.setBlockCursor(true);
- Hashtable var4 = this.getFilesForDirectory(var1, var2);
- var3.setBlockCursor(false);
- var3.setCursor(Cursor.getPredefinedCursor(0));
- return var4;
- }
-
- public Hashtable getFilesForDirectory(ESCFile var1, boolean var2) {
- if (!((File)var1).isDirectory()) {
- return new Hashtable();
- } else {
- Hashtable var3 = new Hashtable();
- Enumeration var4 = FileHandler.list(var1, ESCApplication.getSupportedFlavors()).elements();
-
- while(var4 != null && var4.hasMoreElements()) {
- ESCFile var5 = this.factoryESCFile((File)var4.nextElement(), true);
- if (((File)var5).exists() && ((File)var5).isDirectory() && var2) {
- Enumeration var6 = this.getFilesForDirectory(var5, var5.isRecursive()).elements();
-
- while(var6 != null && var6.hasMoreElements()) {
- ESCFile var7 = (ESCFile)var6.nextElement();
- var3.put(((File)var7).getAbsolutePath(), var7);
- }
- } else if (((File)var5).exists() && ((File)var5).isFile()) {
- var3.put(((File)var5).getAbsolutePath(), var5);
- }
- }
-
- return var3;
- }
- }
-
- public Hashtable getModifiedFilesForDir(ESCFile var1, boolean var2) {
- if (!((File)var1).isDirectory()) {
- return new Hashtable();
- } else {
- Hashtable var3 = new Hashtable();
- Enumeration var4 = FileHandler.list(var1, ESCApplication.getSupportedFlavors()).elements();
-
- while(var4 != null && var4.hasMoreElements()) {
- ESCFile var5 = this.factoryESCFile((File)var4.nextElement(), true);
- if (((File)var5).exists() && ((File)var5).isDirectory() && var2) {
- Enumeration var6 = this.getModifiedFilesForDir(var5, var5.isRecursive()).elements();
-
- while(var6 != null && var6.hasMoreElements()) {
- ESCFile var7 = (ESCFile)var6.nextElement();
- var3.put(((File)var7).getAbsolutePath(), var7);
- }
- } else if (((File)var5).exists() && this.isModified(var5)) {
- var3.put(((File)var5).getAbsolutePath(), var5);
- }
- }
-
- return var3;
- }
- }
-
- protected boolean isModified(ESCFile var1) {
- File var2 = new File(((File)var1).getAbsolutePath());
- Date var3 = new Date(var2.lastModified());
- long var4 = var3.getTime();
- Date var6 = var1.getValidationDate();
- long var7 = var6.getTime();
- return ((File)var1).exists() && ((File)var1).isFile() && (var1.isVirgin() || var4 > var7);
- }
-
- private void updateTheRootName() {
- ESCWindow var1 = (ESCWindow)BaseApplication.getApplication().getMainWindow(this);
- var1.updateTheRootName(((BaseDocument)this).getName());
- }
-
- public InputSource resolveEntity(String var1, String var2) throws IOException, SAXException {
- URI var3 = new URI(var2);
- this.bur.setSilent(true);
- URI var4 = this.bur.resolve(var3);
- if (var4 == null) {
- var4 = URI.makeStringURI("");
- }
-
- if (var4.getFullName().startsWith("file:////")) {
- InputSource var6 = new InputSource();
- var6.setSystemId(var4.getFullName());
- var6.setCharacterStream(var4.createReader());
- return var6;
- } else if (var3 == var4) {
- return null;
- } else {
- InputStream var5 = var4.createInputStream();
- return new InputSource(var5);
- }
- }
-
- protected static InputSource createInputSource(URI var0) {
- InputSource var1 = new InputSource();
- if (!var0.hasPersistence()) {
- if (var0.getBaseURI() != null) {
- var1.setSystemId(var0.getBaseURI().getFullName());
- }
- } else {
- var1.setSystemId(var0.getFullName());
- }
-
- try {
- var1.setCharacterStream(var0.createReader());
- } catch (IOException var3) {
- }
-
- return var1;
- }
-
- public URI resolve(URI var1) {
- return var1.exists() ? var1 : null;
- }
- }
-